<?php

namespace App;

use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use SoftDeletes;

    use Notifiable;

    protected $dates = ['deleted_at'];

    protected $guarded = [];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function articles()
    {
        return $this->hasMany(Article::class);
    }

    /**
     * 用户收藏的文章
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function collectArticles()
    {
        return $this->belongsToMany(Article::class, 'collections')->withTimestamps();
    }

    public function discoveries()
    {
        return $this->belongsToMany(Category::class, 'discoveries')->withTimestamps();
    }

    public function advices()
    {
        return $this->hasMany(Advices::class);
    }

    public function postCategories()
    {
        return $this->hasMany(PostCategories::class);
    }
}
